﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hi_Baidu.Triggers;
using Hi_Baidu.Packet;

namespace Hi_Baidu.Notify
{
    /// <summary>
    ///     任务栏提示基类，提供了所有任务栏提示类基础操作
    /// </summary>
    public abstract class Notify : INotify, ITrigger, IMetaData
    {
        public Notify(String Key, InPackage inpackage, NotifyType.NOTIFYTYPE NotifyType, Object Tag)
        {
            this.key = Key;
            this.notifyType = NotifyType;
            this.notifyPackage = inpackage;
            this.tag = Tag;
        }

        public Notify(String Key, String username, NotifyType.NOTIFYTYPE NotifyType, Object Tag, String SendTime, String Content)
        {
            this.key = Key;
            this.username = username;
            this.notifyType = NotifyType;
            this.tag = Tag;
            this.sendTime = SendTime;
            this.content = Content;
        }

        private String content;

        public String Content
        {
            get { return content; }
            set { content = value; }
        }

        private String sendTime;

        public String SendTime
        {
            get { return sendTime; }
            set { sendTime = value; }
        }
        protected String username;

        protected String Username
        {
            get { return username; }
            set { username = value; }
        }
        protected NotifyType.NOTIFYTYPE notifyType;
        /// <summary>
        ///     当前提示类型
        /// </summary>
        internal NotifyType.NOTIFYTYPE NotifyType
        {
            get { return notifyType; }
        }
        private InPackage notifyPackage;
        /// <summary>
        ///     提示关联的网络输入包
        /// </summary>
        public InPackage NotifyPackage
        {
            get { return notifyPackage; }
        }

        private Object tag;
        /// <summary>
        ///     附加属性
        /// </summary>
        public Object Tag
        {
            get { return tag; }
        }

        #region INotify 成员

        public string GetUsername()
        {
            if (this.notifyPackage is BaseInPackage && this.notifyPackage != null)
            {
                return (this.NotifyPackage as BaseInPackage).GetUsername();
            }
            else if (this.notifyPackage == null)
            {
                return this.username;
            }
            return "";
        }

        public DateTime GetTime()
        {
            if (this.notifyPackage is BaseInPackage && this.notifyPackage != null)
            {
                return (this.NotifyPackage as BaseInPackage).GetTime();
            }
            else if (this.notifyPackage == null)
            {
                return DateTime.Parse(this.sendTime);
            }
            return DateTime.MaxValue;
        }

        public new NotifyType.NOTIFYTYPE GetType()
        {
            return this.notifyType;
        }

        #endregion

        #region ITrigger 成员

        public abstract void Trigger();

        #endregion

        #region IMetaData 成员

        private String key;
        public string Key
        {
            get
            {
                return key;
            }
            set
            {
                key = value;
            }
        }

        #endregion
    }
}
